
class Stack {

    stack: Array<any>
    constructor() {
        this.stack = []
    }
    // 入栈
    push(item: any) {
        return this.stack.push(item)
    }
    // 出栈
    pop() {
        return this.stack.pop()
    }
    //  获取栈顶元素
    peek(): any {
        return this.stack[this.stack.length - 1]
    }
    //  获取栈的长度
    length(): Number {
        return this.stack.length
    }
    //  栈是否为空
    isEmpty(): Boolean {
        return this.stack.length === 0
    }
    //  toString
    toString(): String {
        let stackString: String = '';
        for (let index = 0; index < this.stack.length; index++) {
            const element: any = this.stack[index];
            stackString += element
        }
        return stackString
    }
    printTable(){
        console.table(this.stack)
      
    }
    _toString(){
        return Object.prototype.toString
    }
}